# importing modules
import numpy as np
from random import gauss
import sys
import math


# Gaussian distribution for life-times, constants from article "Measurement of the relativistic time using mesons"
meson_lifetime = 2.2e-6
meson_variance = 0.2e-6


# observer's inputs with checking
print "measurement altitude [in meters from 0 to 3000]"
height = float(raw_input(">>> "))
if not (height >= 0 and height <= 3000):
    sys.exit('Check your altitude. \nScript stopped.')
print "collection time [in hours from 1 to 10]"
time = float(raw_input(">>> "))
if not (time >= 1 and time <= 10):
    sys.exit('Check your collecting time. \nScript stopped.')
    
# Equation was found by plotting meson counts at h1, h2 and assuming exponential collection over height. Numbers from the article above.   
true_count_value = 407.7899493562 * math.exp(0.000168954 * height)


# average count
poisson_counts = np.random.poisson(time * true_count_value, 1)
average_count = poisson_counts / time


# finding life-times and writing to file
myfile = open('data_file.txt', 'w')

myfile.write("average number of mesons counted: %3d\nobserver's altitude: %gm\ncollection time: %sh\nlife-time:\n" % (average_count, height, time))

i = 0
while i < average_count:
    i = i + 1
    life_time = gauss(meson_lifetime, meson_variance)
    myfile.write('\n')
    myfile.write('%.8E' % life_time)
myfile.close()


print '\ndata collected. open data_file.txt\n'
